import { CanActivateFn } from '@angular/router';
import { getUserId } from './api/request';
import { AlertController } from '@ionic/angular';

export const authUserGuard: CanActivateFn = async (route, state) => {
  const uid: any = getUserId()
  if (uid) {
    return true
  }
  
  // 拦截
  const alertController = new AlertController()
  const alert = await alertController.create({
    header: '未知的用户',
    message: '当前登录已过期，请重新登录',
    buttons: [{
      text: 'OK',
      handler: () => {
        location.href = "/starnight-student/login"
      }
    }],
  })
  await alert.present()
  return false
}
